﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="InternalLoggerService.cs" company="SingularityShift.com">
//   Copyright (c) 2010 SingularityShift.com. All rights reserved.
// </copyright>
// <author>Ben McClure</author>
// <email>ben@singularityshift.com</email>
// <date>12/1/2010</date>
// <summary>
//   Implements the IInternalLoggerService interface, providing a logging-framework-agnostic
//   method of logging data.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace GameLib.Util
{
    #region Using Directives

    using System.Diagnostics.CodeAnalysis;

    using SingularityShift.ObjectModel.Util;

    using Slf;

    #endregion

    /// <summary>
    /// This is basically a second façade wrapped around SLF, thus allowing you to minimize dependencies on SLF to
    /// this single class and providing your own API. Should you every decide to dump SLF, you only need to change
    /// this class and you are done. 
    /// </summary>
    /// <remarks>
    /// Ben McClure, 12/1/2010. 
    /// </remarks>
    public sealed class InternalLoggerService : AbstractLoggerHelper
    {
        #region Constructors and Destructors

        /// <summary> 
        /// Prevents a default instance of the <see cref="InternalLoggerService"/> class from being created. Initializes a new instance of the <see cref="InternalLoggerService"/> class. Default constructor.
        /// </summary>
        /// <remarks> Ben McClure, 12/10/2010. </remarks>
        private InternalLoggerService()
        {
            // for simplicity, let's just plug in a console logger
            // right in the constructor of the service
            // This should be removed for release...
            LoggerService.SetLogger(new ConsoleLogger());
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets Instance.
        /// </summary>
        public static InternalLoggerService Instance
        {
            get
            {
                return NestedLoggerService._instance;
            }
        }

        #endregion

        #region Implemented Interfaces

        #region ILoggerService

        /// <summary>
        /// The log debug. 
        /// </summary>
        /// <remarks>
        /// Ben McClure, 12/1/2010. 
        /// </remarks>
        /// <param name="message">
        /// The message. 
        /// </param>
        public override void LogDebug(string message)
        {
            GetLogger().Debug(message);
        }

        /// <summary>
        /// The log error. 
        /// </summary>
        /// <remarks>
        /// Ben McClure, 12/1/2010. 
        /// </remarks>
        /// <param name="message">
        /// The message. 
        /// </param>
        public override void LogError(string message)
        {
            GetLogger().Error(message);
        }

        /// <summary>
        /// The log fatal. 
        /// </summary>
        /// <remarks>
        /// Ben McClure, 12/1/2010. 
        /// </remarks>
        /// <param name="message">
        /// The message. 
        /// </param>
        public override void LogFatal(string message)
        {
            GetLogger().Fatal(message);
        }

        /// <summary>
        /// The log info. 
        /// </summary>
        /// <remarks>
        /// Ben McClure, 12/1/2010. 
        /// </remarks>
        /// <param name="message">
        /// The message. 
        /// </param>
        public override void LogInfo(string message)
        {
            GetLogger().Info(message);
        }

        /// <summary>
        /// The log warning. 
        /// </summary>
        /// <remarks>
        /// Ben McClure, 12/1/2010. 
        /// </remarks>
        /// <param name="message">
        /// The message. 
        /// </param>
        public override void LogWarning(string message)
        {
            GetLogger().Warn(message);
        }

        #endregion

        #endregion

        #region Methods

        /// <summary>
        /// The get logger.
        /// </summary>
        /// <returns>
        /// The primary <see cref="ILogger"/> for this library
        /// </returns>
        private static ILogger GetLogger()
        {
            return LoggerService.GetLogger("GameLib");
        }

        #endregion

        // ReSharper disable ClassNeverInstantiated.Local

        /// <summary>
        /// The nested logger service.
        /// </summary>
        private class NestedLoggerService
        {
            // ReSharper restore ClassNeverInstantiated.Local
            // ReSharper disable InconsistentNaming
            #region Constants and Fields

            /// <summary> The instance </summary>
            [SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules",
                "SA1304:NonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter",
                Justification = "Reviewed. Suppression is OK here.")]
            [SuppressMessage("Microsoft.StyleCop.CSharp.NamingRules",
                "SA1307:AccessibleFieldsMustBeginWithUpperCaseLetter",
                Justification = "Reviewed. Suppression is OK here.")]
            internal static readonly InternalLoggerService _instance = new InternalLoggerService();

            #endregion

            // ReSharper restore InconsistentNaming
        }
    }
}